package router

import (
	"yuanxin-admin/api/v1"
	"yuanxin-admin/internal/common/auth"
	. "yuanxin-admin/internal/middleware"

	"gitee.com/botaoshow/yuanxin/web/middleware"
	"github.com/gin-gonic/gin"
)

// SetupRouter 初始化路由
func SetupRouter(r *gin.Engine) *gin.Engine {
	r.Static("/uploads", "./uploads")
	r.Use(middleware.CorsHandler())
	r.Use(middleware.JsonErrorHandler())
	r.Use(auth.HandleApi())

	sysRouterGroup := r.Group("/api/sys")
	{
		var SysDeptController = v1.NewSysDeptController()
		var SysDictController = v1.NewSysDictController()
		var SysLogController = v1.NewSysLogController()
		var SysMenuController = v1.NewSysMenuController()
		var SysParamsController = v1.NewSysParamsController()
		var SysRoleController = v1.NewSysRoleController()
		var SysController = v1.NewSysController()
		var SysUrlController = v1.NewSysUrlController()
		var SysUserController = v1.NewSysUserController()

		sysRouterGroup.GET("/webInfo", SysController.WebInfo)
		sysRouterGroup.GET("/website/query", SysController.WebInfoQuery)
		sysRouterGroup.POST("/website/sync", SysController.WebInfoSync)
		sysRouterGroup.POST("/website/syncBatch", SysController.WebInfoSyncBatch)
		sysRouterGroup.GET("/getRsaPublicKey", SysController.GetRsaPublicKey)

		sysRouterGroup.GET("/user/imageCaptcha", SysUserController.ImageCaptcha)
		sysRouterGroup.POST("/user/login", LoginLog(), SysUserController.Login)
		sysRouterGroup.POST("/user/logout", SysUserController.Logout)
		sysRouterGroup.POST("/user/changePassword", SysUserController.ChangePassword)
		sysRouterGroup.GET("/user/list", SysUserController.QueryList)
		sysRouterGroup.POST("/user/updateStatus/:id/:status", SysUserController.UpdateStatus)
		sysRouterGroup.POST("/user/save", SysUserController.Save)
		sysRouterGroup.POST("/user/update/:id", SysUserController.Update)
		sysRouterGroup.POST("/user/delete/:id", SysUserController.Delete)

		sysRouterGroup.GET("/menu/listAll", SysMenuController.ListAll)
		sysRouterGroup.GET("/menu/roleMenuAll", SysMenuController.RoleMenuAll)
		sysRouterGroup.GET("/menu/roleMenu", SysMenuController.RoleMenu)
		sysRouterGroup.GET("/menu/getRoleMenuIds/:roleId", SysMenuController.GetRoleMenuIds)
		sysRouterGroup.POST("/menu/updateRoleMenus/:roleId", SysMenuController.UpdateRoleMenus)
		sysRouterGroup.POST("/menu/create", SysMenuController.Create)
		sysRouterGroup.POST("/menu/update/:id", SysMenuController.Update)
		sysRouterGroup.GET("/menu/queryById/:id", SysMenuController.QueryById)
		sysRouterGroup.POST("/menu/deleteById/:id", SysMenuController.DeleteById)

		sysRouterGroup.POST("/dept/save", SysDeptController.Save)
		sysRouterGroup.POST("/dept/update/:id", SysDeptController.Update)
		sysRouterGroup.POST("/dept/remove/:id", SysDeptController.Remove)
		sysRouterGroup.GET("/dept/list", SysDeptController.List)

		sysRouterGroup.GET("/dict/queryPage", SysDictController.QueryPage)
		sysRouterGroup.GET("/dict/query/:code", SysDictController.Query)
		sysRouterGroup.GET("/dict/queryListData/:id", SysDictController.QueryListData)
		sysRouterGroup.GET("/dict/queryTreeData/:id", SysDictController.QueryTreeData)
		sysRouterGroup.POST("/dict/create", SysDictController.Create)
		sysRouterGroup.POST("/dict/update/:id", SysDictController.Update)
		sysRouterGroup.POST("/dict/delete/:id", SysDictController.Delete)
		sysRouterGroup.POST("/dict/option/create", SysDictController.OptionCreate)
		sysRouterGroup.POST("/dict/option/update/:id", SysDictController.OptionUpdate)
		sysRouterGroup.POST("/dict/option/delete/:id", SysDictController.OptionDelete)

		sysRouterGroup.GET("/params/query", SysParamsController.Query)
		sysRouterGroup.POST("/params/sync", SysParamsController.Sync)

		sysRouterGroup.GET("/role/query", SysRoleController.Query)
		sysRouterGroup.POST("/role/addUrl", SysRoleController.AddUrl)
		sysRouterGroup.POST("/role/removeUrl", SysRoleController.RemoveUrl)

		sysRouterGroup.GET("/log/login", SysLogController.Login)
		sysRouterGroup.GET("/log/oper", SysLogController.Oper)

		sysRouterGroup.GET("/url/queryList", SysUrlController.QueryList)
		sysRouterGroup.GET("/url/queryWithRolesList", SysUrlController.QueryWithRolesList)
		sysRouterGroup.POST("/url/addUrlToWhitelist", SysUrlController.AddUrlToWhitelist)
		sysRouterGroup.POST("/url/removeUrlFormWhitelist", SysUrlController.RemoveUrlFormWhitelist)
		sysRouterGroup.GET("/url/queryWhitelist", SysUrlController.QueryWhitelist)
	}

	return r
}
